const fs = require('fs');
const path = require('path');
const eventEmitter = require('events');
const http = require('http');

let fileName1 = path.resolve(__dirname, 'data1.txt');
let fileName2 = path.resolve(__dirname, 'data1-ba.txt');

let rs = fs.createReadStream(fileName1);
let ws = fs.createWriteStream(fileName2);
console.log('rs 对象：');
console.log('rs 是否继承自 events:')
console.log(rs instanceof eventEmitter);  //true
console.log('process 是否继承自 events:')
console.log(process instanceof eventEmitter);  //true
console.log('http 是否继承自 events:')
console.log(http instanceof eventEmitter);  //false
// console.log(rs);
// rs.pause();
// rs.read();
rs.pipe(ws);

//结束
rs.on('data', function(){
    console.log('拷贝完成 data 触发');
})

rs.on('drain', function(){
    console.log('拷贝完成 drain 触发');
})

rs.on('end', function(){
    console.log('拷贝完成 end 触发');
    // console.log(rs);
})

rs.on('readable', function(){
    console.log('拷贝完成 readable 触发');
})

// rs.on('error', function(){
//     console.log('拷贝完成 error 触发');
// })